<?php 

$page           = (!empty($_GET['page-id']) && is_numeric($_GET['page-id'])) ? $_GET['page-id'] : 1;
$filter_keyword = (!empty($_GET['query'])) ? Wo_Secure($_GET['query']) : '';
$filter_type    = '';
$db->pageLimit  = 50;


if (!empty($filter_keyword)) {
  $sql   = "(
    `page_id`          LIKE '%$filter_keyword%' OR 
    `page_name`        LIKE '%$filter_keyword%' OR
    `page_title`       LIKE '%$filter_keyword%' OR
    `page_description` LIKE '%$filter_keyword%'
  )";
  
  $pages = $db->where($sql)->orderBy('page_id', 'DESC')->objectbuilder()->paginate(T_PAGES, $page);
} 

else {
  $pages = $db->objectbuilder()->orderBy('page_id', 'DESC')->paginate(T_PAGES, $page);
}

if (($page > $db->totalPages) && !empty($_GET['page-id'])) {
  header("Location: " . Wo_LoadAdminLinkSettings('manage-pages'));
  exit();
}

?>

<div class="container-fluid">
    <div class="block-header">
        <h2>功能管理 > 页面</h2>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
          <div class="col-lg-3 col-md-3">
            <div class="info-box bg-pink hover-expand-effect">
                <div class="icon">
                    <i class="material-icons">flag</i>
                </div>
                <div class="content">
                    <div class="text">总页面数</div>
                    <div class="number count-to" data-from="0" data-to="<?php echo Wo_CountAllData('page'); ?>" data-speed="1000" data-fresh-interval="20"></div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-3 ">
            <div class="info-box bg-pink hover-expand-effect">
                <div class="icon">
                    <i class="material-icons">thumb_up</i>
                </div>
                <div class="content">
                    <div class="text">总点赞数</div>
                    <div class="number count-to" data-from="0" data-to="<?php echo Wo_CountPageData('likes'); ?>" data-speed="1000" data-fresh-interval="20"></div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-3 ">
            <div class="info-box bg-pink hover-expand-effect">
                <div class="icon">
                    <i class="material-icons">mode_edit</i>
                </div>
                <div class="content">
                    <div class="text">总文章数</div>
                    <div class="number count-to" data-from="0" data-to="<?php echo Wo_CountPageData('pages_posts'); ?>" data-speed="1000" data-fresh-interval="20"></div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-3 ">
            <div class="info-box bg-pink hover-expand-effect">
                <div class="icon">
                    <i class="material-icons">check_circle</i>
                </div>
                <div class="content">
                    <div class="text">认证页面</div>
                    <div class="number count-to" data-from="0" data-to="<?php echo Wo_CountPageData('verified_pages'); ?>" data-speed="1000" data-fresh-interval="20"></div>
                </div>
            </div>
        </div>
        
        <div class="col-lg-12 col-md-12">
            <div class="card">
                <div class="header">
                    <h2>管理 & 编辑页面</h2>
                </div>
                <div class="body">
                    <div class="row">
                      <div class="col-md-4" style="margin-bottom:0;">
                        <form method="get" action="<?php echo Wo_LoadAdminLinkSettings('manage-pages'); ?>">
                          <div class="row">
                            <div class="col-md-11">
                              <div class="form-group form-float">
                                  <div class="form-line">
                                      <input type="text" name="query" id="query" class="form-control" value="<?php echo($filter_keyword); ?>">
                                      <label class="form-label search-form">
                                        搜索页面ID，页面名称，页面标题.
                                      </label>
                                  </div>
                              </div>
                            </div>
                            <div class="col-md-1">
                               <button class="btn btn-info">搜索</button>
                            </div>
                          </div>
                          <div class="clearfix"></div>
                        </form>
                      </div>
                    </div>
                   <input type="hidden" id="hash_id" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                   <div class="clearfix"></div>
                    <div class="table-responsive1">
                        <table class="table table-bordered table-striped table-hover">
                            <thead>
                            <tr>
                              <th>ID</th>
  					                  <th>页面名称</th>
  					                  <th>所有者</th>
  					                  <th>分类</th>
  					                  <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                              <?php 
        				                foreach ($pages as $pagelist) {
                                  $wo['pagelist']          = Wo_PageData($pagelist->page_id);
                                  $wo['pagelist']['owner'] = Wo_UserData($pagelist->user_id);
        				                  echo Wo_LoadAdminPage('manage-pages/list');
        				                }
				                      ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="wo-admincp-feturepager">
                        <div class="pull-left">
                            <span>
                              <?php echo "显示 $page 一共 " . $db->totalPages; ?>
                            </span>
                        </div>
                        <div class="pull-right">
                          <nav>
                              <ul class="pagination">
                                  <li>
                                    <a href="<?php echo Wo_LoadAdminLinkSettings('manage-pages?page-id=1'); ?>" class="waves-effect" title='第一页'>
                                        <i class="material-icons">first_page</i>
                                    </a>
                                  </li>
                                  <?php if ($page > 1) {  ?>
                                    <li>
                                        <a href="<?php echo Wo_LoadAdminLinkSettings('manage-pages?page-id=' . ($page - 1)); ?>" class="waves-effect" title='上一页'>
                                            <i class="material-icons">chevron_left</i>
                                        </a>
                                    </li>
                                  <?php  } ?>

                                  <?php 
                                    $nums       = 0;
                                    $nums_pages = ($page > 4) ? ($page - 4) : $page;

                                    for ($i=$nums_pages; $i <= $db->totalPages; $i++) { 
                                      if ($nums < 20) {
                                  ?>
                                    <li class="<?php echo ($page == $i) ? 'active' : ''; ?>">
                                      <a href="<?php echo Wo_LoadAdminLinkSettings('manage-pages?page-id=' . ($i)); ?>" class="waves-effect">
                                        <?php echo $i ?>   
                                      </a>
                                    </li>

                                  <?php } $nums++; }?>

                                  <?php if ($db->totalPages > $page) { ?>
                                    <li>
                                        <a href="<?php echo Wo_LoadAdminLinkSettings('manage-pages?page-id=' . ($page + 1)); ?>" class="waves-effect" title="下一页">
                                            <i class="material-icons">chevron_right</i>
                                        </a>
                                    </li>
                                  <?php } ?>
                                  <li>
                                    <a href="<?php echo Wo_LoadAdminLinkSettings('manage-pages?page-id=' . ($db->totalPages)); ?>" class="waves-effect" title='最后一页'>
                                        <i class="material-icons">last_page</i>
                                    </a>
                                  </li>
                              </ul>
                          </nav>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>

function Wo_DeletePage(page_id) {
  if (confirm("您确定要删除此页面吗？") == false) {
    return false;
  }
  hash_id = $('#hash_id').val();
  $('#PageID_' + page_id).fadeOut(300, function() {
    $(this).remove();
  });
  $.get(Wo_Ajax_Requests_File(),{f:'admin_setting',s:'delete_user_page',page_id: page_id, hash_id:hash_id});
}

</script>